
#include <iostream>
#include "SharePtr.h"
#include <vector>

#include <Windows.h>

using namespace std;

class A
{
public:
	A()
	{
		cout << "init" << endl;
	}
	~A()
	{
		cout << "destory" << endl;
	}
};

class B
{
public:
	B(int a)
	{
		cout << "init b " << a << endl;
	}
	~B()
	{
		cout << "destory b " << endl;
	}
};


class Base
{
public:
	Base() { cout << "init base" << endl; }
	virtual ~Base() { cout << "destory base" << endl; }

	void basePrintf()
	{
		cout << __FUNCTION__ << endl;
	}

	virtual	void printf()
	{
		cout << __FUNCTION__  "Base"<< endl;
	}
};

class Test
	:public Base
{
public:
	Test() { cout << "int Test" << endl; }
	virtual ~Test() { cout << "destory Test " << endl; }

	void TestPrintf()
	{
		cout << __FUNCTION__ << endl;
	}

	void printf()
	{
		cout << __FUNCTION__  "test" << endl;
	}
};

void func()
{
	SharePtr<Base> p = staticPointerCast<Base>(makeSharePtr<Test>());
	p->basePrintf();
	p->printf();

	SharePtr<Test> t = dynamicPointerCast<Test>(p);
	if (t != nullptr)
	{
		t->TestPrintf();
		p->printf();
	}
}

void run(SharePtr<Base> v)
{
	while (true)
	{
		Sleep(100);
	}
}
int main()
{	

	func();

	vector<SharePtr<Base>> ver;
	ver.push_back(staticPointerCast<Base>(makeSharePtr<Test>()));
	SharePtr<Base> p = makeSharePtr<Base>();
	ver.push_back(p);
	ver.clear();
	p.reset();
	const SharePtr<Base> v = makeSharePtr<Base>();
	SharePtr<Base> b = constPointerCast<Base>(v);
	b->basePrintf();
	run(p);
	//std::make_shared()
//	std::static_pointer_cast<>
	
	/*SharePtr<A> p(new A());
	std::vector<SharePtr<A>> ver;
	ver.push_back(p);
	ver.push_back(SharePtr<A>(new A()));
	ver.clear();
	SharePtr<A> pp = makeSharePtr<A>();
	func();
	SharePtr<B> pb = makeSharePtr<B>(123);
	cout << "----------" << endl;
	*/
	system("pause");
	return 0;
}